/**
 * Created by Administrator on 2019/1/26.
 */
'use strict';
const Controller = require('egg').Controller;
const config = require('../utils/config');
const uploadRecord = require('../utils/store').uploadRecord;
const compressing = require('compressing');
class LoginController extends Controller {

  /**
   * 获取所有信息
   */
  async getAll() {
    const { ctx } = this;
    const url = await ctx.service.admin.getAll();
    if (url) {
      ctx.body = ctx.helper.sendOk(url);
    } else {
      ctx.body = ctx.helper.sendErr(url);
    }
  }

  // 获取所有的报销文件合集
 async getFileZip() {
    const { ctx } = this;

    try {
      await compressing.zip.compressDir(config.fileDir, config.fileDir + '/allFile.zip')
      ctx.body = ctx.helper.sendOk(config.downPath + '/allFile.zip');
    } catch (error) {
      
    }
  }

  // 获取上传明细记录
  getUploadRecord() {
    const { ctx } = this;

    const res = [];
    for (const key in uploadRecord) {
      res.push(uploadRecord[key]);
    }
    ctx.body = ctx.helper.sendOk(res);
  }
}

module.exports = LoginController;
